export function add_order(order,add){
    let order_ = JSON.parse(localStorage.getItem("order"))||[]
    if (order_.length>0){
        order_.filter(i=>i.id === order.id).length === 0&&order_.push({
            id: order.id,
            count: 1
        })
        
        order_.forEach(i=>{
            if(i.id === order.id){
                if(!add&&i.count>0){
                    i.count--
                }
                if(add){
                    i.count++
                }
            }
        })
        $("#order-badge").text(order_.reduce((acc, curr) => {
            return acc + curr.count
        },0))
        order_ = JSON.stringify(order_)
        localStorage.setItem("order", order_)
    }else{
        order_ = []
        order_.push({
            id: order.id,
            count: 1
        })
        $("#order-badge").text(order_.reduce((acc, curr) => {
            return acc + curr.count
        },0))
        order_ = JSON.stringify(order_)
        localStorage.setItem("order", order_)
    }
   
}



export function order_tage(){
    const order = JSON.parse(localStorage.getItem("order")||"[]")||[]
    const count = order.length>0?order.reduce((p,c)=> p+c.count,0):0;
    return count
}